<?php

use App\Http\Controllers\AttachmentController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\CouponController;
use App\Http\Controllers\DepositController;
use App\Http\Controllers\FormController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LinkController;
use App\Http\Controllers\MailController;
use App\Http\Controllers\ManageController;
use App\Http\Controllers\MediaController;
use App\Http\Controllers\MemberAuthController;
use App\Http\Controllers\MemberController;
use App\Http\Controllers\MemberCouponController;
use App\Http\Controllers\NoticeController;
use App\Http\Controllers\NoticeMessageController;
use App\Http\Controllers\OpenRedController;
use App\Http\Controllers\PosterController;
use App\Http\Controllers\RedController;
use App\Http\Controllers\RedRecordController;
use App\Http\Controllers\SendAccessController;
use App\Http\Controllers\SendRedController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\ShareController;
use App\Http\Controllers\StaffController;
use App\Http\Controllers\SubMessageController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\WxController;
use Illuminate\Support\Facades\Route;
// 后台
Route::group(['prefix'=>'admin'],function(){
    // 无需验证authorized
    // 注册
    Route::post('register', [UserController::class,'register']);
    // 登录
    Route::post('login', [AuthController::class,'login']);
    // 备案信息
    Route::get('bei', [HomeController::class, 'bei']);

    // 验证authorized
    Route::middleware('auth:api')->group(function() {

        // S用户
        Route::group(['prefix'=>'user'],function() {
            // 获取用户信息
            Route::get('get',function() {
                return auth()->user();
            });
            // 修改用户账号密码
            Route::put('update', [UserController::class,'update']);
            // 退出账号登录
            Route::post('logout', [AuthController::class,'logout']);
        });
        // E用户

        //S可发红包用户
        Route::group(['prefix'=>'send-access'],function() {
            // 添加发红包用户
            Route::post('/', [SendAccessController::class, 'store']);
            // 删除发红包用户
            Route::delete('/{id}', [SendAccessController::class, 'destroy']);
            // 可发红包用户列表
            Route::get('/', [SendAccessController::class,'index']);
        });
        //S可发红包用户

        // S首页统计相关接口
        Route::group(['prefix'=>'home'],function() {
            // 首页统计表，获取指定日期的红包相关数据
            Route::get('getStatisticsDate', [Homecontroller::class, 'getStatisticsDate']);
            // 获取首页数据
            Route::get('getInfo', [Homecontroller::class, 'getInfo']);
            // 获取首页每月红包数据
            Route::get('getMonth', [HomeController::class, 'getMonth']);
        });
        // E首页统计相关接口

        // S会员
        Route::group(['prefix'=>'member'],function() {
            // 会员列表
            Route::get('/', [MemberController::class, 'getList']);
            // 会员总数
            Route::get('total', [MemberController::class,'total']);
            // 一个会员信息
            Route::get('/{id}',[MemberController::class,'get']);
            // 修改指定用户余额
            Route::put('/editBalance/{member_id}', [MemberController::class,'edit']);
        });
        // E会员

        // S红包
        Route::group(['prefix'=>'red'],function() {
            // 红包列表
            Route::get('/', [RedController::class, 'getList']);
            // 红包总数
            Route::get('total', [RedController::class,'total']);
            // 删除红包
            Route::delete('/{id}', [RedController::class,'destroy']);
        });
        // E红包

        // S用户素材
        Route::group(['prefix'=>'media'],function() {
            // 等待审核列表
            Route::get('check', [MediaController::class,'checkList']);
            // 待审核素材总数
            Route::get('check/total', [MediaController::class,'checkTotal']);
            // 拒绝审核，删除素材
            Route::post('/remove/{id}', [MediaController::class,'remove']);
            // 素材审核通过
            Route::put('/pass/{id}', [MediaController::class,'pass']);
        });
        // E用户素材

        // 系统卡券
        Route::group(['prefix'=>'coupon'],function() {
            // 待审核卡券总数
            Route::get('check/total', [CouponController::class,'checkTotal']);
            // 等待审核列表
            Route::get('check', [CouponController::class,'checkList']);
            // 通过卡券审核
            Route::put('check/pass/{id}', [CouponController::class,'pass']);
            // 拒绝卡券审核
            Route::post('check/refuse/{id}', [CouponController::class,'refuse']);
            // 拒绝卡券审核并且删除卡券
            Route::post('check/remove/{id}', [CouponController::class,'remove']);
        });
        // 系统卡券

        // S提现
        Route::group(['prefix'=>'deposit'],function() {
            // 提现总数
            Route::get('total', [DepositController::class,'total']);
            // 提现列表
            Route::get('/', [DepositController::class,'getList']);
            // 提现一条申请记录
            Route::put('/{id}', [DepositController::class,'deposit'])
                ->where('id','\d+');
            // 拒绝一条提现申请
            Route::put('refuse/{id}', [DepositController::class,'refuse']);
        });
        // E提现

        // S员工
        Route::group(['prefix'=>'manage'],function() {
            // 获取申请员工二维码链接
            Route::get('qrcode', [ManageController::class,'qrcode']);
            // 检测二维码是否过期||用户是否扫码
            Route::get('test-qrcode', [ManageController::class,'testQrcode']);
            // 添加一位员工
            Route::post('/', [ManageController::class, 'store']);
            // 修改一位员工
            Route::post('/{id}',[ManageController::class, 'edit']);
            // 员工列表
            Route::get('/', [ManageController::class, 'index']);
            // 删除员工
            Route::delete('/{id}', [ManageController::class, 'destroy']);
        });
        // E员工

        // S素材库
        Route::group(['prefix'=>'attachment'],function() {
            // 上传素材
            Route::post('upload',[AttachmentController::class,'upload']);
            // 获取素材列表
            Route::get('getList',[AttachmentController::class,'getList']);
            // 获取素材附件前缀链接
            Route::get('getAttachmentUrl',[AttachmentController::class,'getAttachmentUrl']);
            // 删除素材附件
            Route::delete('delete/{attachment_id}',[AttachmentController::class,'delete']);
        });
        // E素材库

        // S配置
        Route::group(['prefix'=>'setting'],function() {
            // 获取系统的所有配置信息
            Route::get('/', [SettingController::class,'index']);
            // 获取前端入口链接
            Route::get('entry-url', function() {
                return response(["data"=>route('app')]);
            });
            // 设置系统配置
            Route::put('{type}', [SettingController::class,'update']);
            // 上传微信支付证书
            Route::post('uploadWxPayCert', [SettingController::class,'uploadWxPayCert']);
            // 测试远程附件上传
            Route::get('testingAttachment/{storage_type}', [SettingController::class,'testingAttachment']);
            // 自动配置模板消息
            Route::post('message/autoSetTplMessage', [NoticeMessageController::class,'autoSetTplMessage']);
            // 自动配置订阅消息
            Route::post("message/autoSetSubscribeMessage", [NoticeMessageController::class,'autoSetSubscribeMessage']);
        });
        // E配置
    });
});

// 前台客户端
Route::group(['prefix'=>'app'],function() {
    // 登录
    Route::post('login', [MemberAuthController::class,'login']);
    // 微信公众号授权所需配置
    Route::get('getOauthData', [SettingController::class,'getOauthData']);
    // 获取JSAPI配置
    Route::get('jsapi', [WxController::class,'jsapi']);


    // 需要token验证
    Route::middleware(['auth:member'])->group(function() {

        // 配置
        Route::group(['prefix'=>'setting'], function() {
            Route::get('/{setting_type}', [SettingController::class,'getOneSetting']);
        });

        // 用户相关信息
        Route::group(['prefix'=>'member'], function() {
            // 获取登录用户基本信息
            Route::get('/', [MemberController::class,'index']);
        });

        // 素材库
        Route::group(['prefix'=>'media'], function() {
            // 用户素材库列表
            Route::get('/',[MediaController::class,'index']);
            // 上传素材
            Route::post('/',[MediaController::class,'store']);
            // 上传远程附件
            Route::post('remote', [MediaController::class,'remote']);
            // 视频转码
            Route::post('{media_id}/transcoding', [MediaController::class,'transcoding']);
            // 删除素材
            Route::delete('/{id}',[MediaController::class,'destroy']);
            // 素材库内存获取
            Route::get('memory',[MediaController::class,'memory']);
            // 通过一组素材库id返回素材封面
            Route::get('idToThumbs', [MediaController::class,'idToThumbs']);
        });

        // 推广链接
        Route::group(['prefix'=>'link'], function() {
            // 推广链接列表
            Route::get('/', [LinkController::class,'index']);
            // 修改或者新增推广链接
            Route::put('/{id?}',[LinkController::class,'edit']);
            // 获取一个推广链接详情
            Route::get('/{id}',[LinkController::class,'show']);
            // 删除一个推广链接
            Route::delete('/{id}',[LinkController::class,'destroy']);
        });

        // 卡券管理
        Route::group(['prefix'=>'coupon'],function(){
            // 卡券列表
            Route::get('/', [CouponController::class,'index']);
            // 修改或者新增卡券
            Route::put('/{id?}', [CouponController::class,'edit']);
            // 获取一个卡券详情
            Route::get('/{id}', [CouponController::class,'show']);
            // 删除一个卡券
            Route::delete('/{id}', [CouponController::class,'destroy']);
        });

        // 万能表单
        Route::group(['prefix'=>'form'],function(){
            // 表单列表
            Route::get('/', [FormController::class, 'index']);
            // 修改或者新增表单
            Route::put('/{id?}', [FormController::class,'edit']);
            // 获取一个表单详情
            Route::get('/{id}', [FormController::class,'show'])
            ->where("id","\d+");
            // 删除一个表单
            Route::delete('/{id}', [FormController::class,'destroy']);
            // 开红包提交一个红包表单
            Route::post('/{id}', [FormController::class,'store']);
            // 获取红包表单列表
            Route::get('/red-list/{red_id}', [FormController::class,'redList']);
        });

        // 员工管理
        Route::group(['prefix'=>'staff'], function() {
            // 员工列表
            Route::get('/', [StaffController::class, 'index']);
            // 删除员工
            Route::delete('/{id}', [StaffController::class, 'destroy']);
            // 通过审核员工
            Route::get('/pass/{id}', [StaffController::class, 'pass']);
            // 获取申请员工二维码地址
            Route::get('apply_url', [StaffController::class, 'applyUrl']);
            // 测试申请员工二维码链接是否过期
            Route::get('test_apply_url', [StaffController::class, 'testApplyUrl']);
        });

        // 红包
        Route::group(['prefix'=>'red'], function() {
            // 发红包
            Route::post('/', [SendRedController::class,'index']);
            // 修改红包
            Route::post('/{id}', [RedController::class,'edit'])
                ->where("id","\d+");
            // 首页红包列表
            Route::get('/', [RedController::class,'index']);
            // 首页获取一个红包详情
            Route::get('/{id}', [RedController::class,'show'])
            ->where("id",'\d+');
            // 首页列表红包总数
            Route::get('homeListTotal', [RedController::class,'homeListTotal']);
            // 开红包
            Route::post('/open', [OpenRedController::class,'index']);
            // 获取一个开启红包的开启奖品记录
            Route::get('/record/{red_id}', [RedRecordController::class,'show']);
            // 获取当前用户红包列表
            Route::get('/member/list', [RedController::class,'member']);
            // 停止发红包
            Route::post('/stop/{id}', [RedController::class,'stop']);
            // 开始发红包
            Route::post('/start/{id}', [RedController::class,'start']);
            // 删除红包
            Route::delete('/{id}', [RedController::class,'destroy']);
            // 获取红包手续费比例
            Route::get('/gain', [RedController::class,'gain']);
            // 验证当前用户是否有权限发红包
            Route::get('/checkAccess', [RedController::class,'checkAccess']);
            // 获取生成红包海报所需数据
            Route::get('/poster/{id}',[PosterController::class,"show"]);
        });

        // 红包记录
        Route::group(['prefix'=>'red-record'], function() {
            // 获取一个红包的开启记录
            Route::get('/{id}', [RedRecordController::class,'index'])
                ->where("id","\d+");
        });

        // 提现
        Route::group(['prefix'=>'deposit'], function() {
            // 获取用户可提现金额
            Route::get('money', [DepositController::class,'money']);
            // 申请提现
            Route::post('/', [DepositController::class,'store']);
            // 提现列表
            Route::get('/', [DepositController::class,'index']);
        });

        // 用户卡券
        Route::group(['prefix'=>'member-coupon'], function() {
            // 用户卡券列表
            Route::get('/', [MemberCouponController::class,'index']);
            // 删除卡券
            Route::delete('/{id}', [MemberCouponController::class,'destroy']);
            // 用户卡券详情
            Route::get('/{id}', [MemberCouponController::class,'show'])
                ->where('id','\d+');
            // 获取卡券核销的url
            Route::get('/check_url', [MemberCouponController::class,'checkUrl']);
            // 检测核销卡券链接是否过期
            Route::get('/test_check_url', [MemberCouponController::class,'testCheckUrl']);
        });

        // 用户财务相关
        Route::group(['prefix'=>'finance'], function() {
            // 红包收入记录
            Route::get('/income', [RedRecordController::class,'income']);
        });

        // 系统公告
        Route::group(['prefix'=>'notice'], function() {
            // 获取系统公告
            Route::get('/', [NoticeController::class,'show']);
            // 确认已读公告
            Route::post('/', [NoticeController::class,'store']);
        });

        // 微信相关
        Route::group(['prefix'=>'wx'],function() {
            Route::get('hintAttention', [WxController::class,'hintAttention']);
        });

        // 订阅消息
        Route::group(['prefix'=>'sub-message'],function() {
            Route::get('testShowSubMessage', [SubMessageController::class,'testShowSubMessage']);
        });

        // 邮件
        Route::group(['prefix'=>'mail'],function() {
            Route::post("/red-form/{red_id}", [MailController::class,"RedForm"]);
        });

        // 分享
        Route::group(['prefix'=>'share'],function() {
            // 通过一个分享id获取分享者id和分享的红包id
            Route::get("/{share_id}", [ShareController::class,'show']);
            // 获取一个红包的分享数据
            Route::get("/share-data/{red_id}", [ShareController::class,'find']);
        });
    });
});
